package com.tledu.meeting_room.controller;

import com.tledu.common.annotation.Log;
import com.tledu.common.core.controller.BaseController;
import com.tledu.common.core.domain.AjaxResult;
import com.tledu.common.core.page.TableDataInfo;
import com.tledu.common.enums.BusinessType;
import com.tledu.common.utils.poi.ExcelUtil;
import com.tledu.meeting_info.domain.MeetingRoom;
import com.tledu.meeting_info.service.IMeetingRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会议室管理Controller
 *
 * @author ruoyi
 * @date 2024-08-29
 */
@RestController
@RequestMapping("/meeting_room/room")
public class MeetingRoomController extends BaseController {
    @Autowired
    private IMeetingRoomService meetingRoomService;

    /**
     * 查询会议室管理列表
     */
    @PreAuthorize("@ss.hasPermi('meeting_room:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(MeetingRoom meetingRoom) {
        startPage();
        List<MeetingRoom> list = meetingRoomService.selectMeetingRoomList(meetingRoom);
        return getDataTable(list);
    }

    // 查看按钮
    @GetMapping("/{id}")
    public AjaxResult room(@PathVariable Integer id) {
        MeetingRoom meetingRoom=meetingRoomService.selectRoomId(id);
        return AjaxResult.success(meetingRoom);
    }

    /**
     * 导出会议室管理列表
     */
    @PreAuthorize("@ss.hasPermi('meeting_room:room:export')")
    @Log(title = "会议室管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeetingRoom meetingRoom) {
        List<MeetingRoom> list = meetingRoomService.selectMeetingRoomList(meetingRoom);
        ExcelUtil<MeetingRoom> util = new ExcelUtil<MeetingRoom>(MeetingRoom.class);
        util.exportExcel(response, list, "会议室管理数据");
    }

    /**
     * 获取会议室管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('meeting_room:room:query')")
    @GetMapping(value = "/success/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(meetingRoomService.selectMeetingRoomById(id));
    }

    /**
     * 新增会议室管理
     */
    @PreAuthorize("@ss.hasPermi('meeting_room:room:add')")
    @Log(title = "会议室管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeetingRoom meetingRoom) {
        return toAjax(meetingRoomService.insertMeetingRoom(meetingRoom));
    }

    /**
     * 修改会议室管理
     */
    @PreAuthorize("@ss.hasPermi('meeting_room:room:edit')")
    @Log(title = "会议室管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeetingRoom meetingRoom) {
        return toAjax(meetingRoomService.updateMeetingRoom(meetingRoom));
    }

    /**
     * 逻辑删除会议室
     */
    @PutMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(meetingRoomService.deleteMeetingRoomByIds(ids));
    }
}
